package com.neusoft.controller;

import com.neusoft.core.Cart;
import com.neusoft.core.CommonResult;
import com.neusoft.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RefreshScope
@RestController
@RequestMapping("/CartController")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping("/Carts")
    public CommonResult<List> listCart(@ModelAttribute Cart cart) throws Exception{
        List<Cart> list = cartService.listCart(cart);
        return new CommonResult(200,"success(10410)",list);
    }

    @PostMapping("/Cart")
    public CommonResult<Integer> saveCart(@RequestBody Cart cart) throws Exception{
        int result = cartService.saveCart(cart);
        return new CommonResult(200,"success(10410)",result);
    }
    @PutMapping("/Cart")
    public CommonResult<Integer> updateCart(@RequestBody Cart cart) throws Exception{
        int result = cartService.updateCart(cart);
        return new CommonResult(200,"success(10410)",result);
    }
    @DeleteMapping("/Cart")
    public CommonResult<Integer> removeCart(@RequestBody Cart cart) throws Exception{
        int result = cartService.removeCart(cart);
        return new CommonResult(200,"success(10410)",result);
    }
}